{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a046d0f0-8c54-460d-82d4-71de7b05d89f",
   "metadata": {},
   "source": [
    "#### numpy创建数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4d240899-1228-4941-9f09-31b44bd8a4aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5, 6])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "# 创建Numpy数组\n",
    "a = np.array([1,2,3,4,5,6]);\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e32a86d4-0ae8-4ae7-87a9-3f3922ab0779",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = np.array([\n",
    "    [1,2,3],\n",
    "    [4,5,6]\n",
    "])\n",
    "A"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "58aa39e1-fe1f-42a3-81d6-83ba414cace6",
   "metadata": {},
   "source": [
    "#### Numpy数组的属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8753506c-306d-4d19-bd74-fdaeca2a0ed2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取数组的维度\n",
    "A.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7c2d7863-ce6f-492c-bf35-43f4543cb680",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 3)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取数组在每个维度上的大小\n",
    "A.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6228502a-fffb-478d-9587-5db9de4d3fbc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取数组元素的总个数\n",
    "A.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c95d7d26-e9d6-4df1-9a89-ed78eb7160fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('int64')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取数组中元素的类型\n",
    "A.dtype"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2c3f7f3-ff79-4449-b0ba-92ff4a30c080",
   "metadata": {},
   "source": [
    "#### 创建数组的方式"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9938086-405d-4d62-976c-cfa3ba669d50",
   "metadata": {},
   "source": [
    "#### Zeros   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "dbcdb665-4543-4dc6-baaf-056d2547ad43",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 0 0]\n",
      " [0 0 0]]\n"
     ]
    }
   ],
   "source": [
    "# 创建2行3列元素全都是 0 的数组\n",
    "# np.zeros(shape, dtype=float, order='C')\n",
    "A = np.zeros((2,3),dtype=int)\n",
    "print(A)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f4d5e785-1cca-4bd5-957d-a629cdcd6527",
   "metadata": {},
   "source": [
    "#### Zeros_like"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c5d71b8c-a2d6-457d-aad4-83ca7672a257",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0.],\n",
       "       [0., 0., 0.]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建一个形状和数据类型都与给定数组相同，但元素全为 0 的新数组。\n",
    "# np.zeros_like(array, dtype=None, order='K', subok=True, shape=None)\n",
    "np.zeros_like(A)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7684a158-0a8b-4d3e-a69a-ba10468705e2",
   "metadata": {},
   "source": [
    "#### Ones"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1762abc0-714e-41fa-8488-ffac5787f55e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1.],\n",
       "       [1., 1., 1.]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建一个指定形状的数组，并用 1 填充。\n",
    "# np.ones(shape, dtype=None, order='C')\n",
    "np.ones((2,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fada6db-157f-4a77-a16f-8b03f2a039e1",
   "metadata": {},
   "source": [
    "#### Ones_like "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "a8706ea2-a105-4b6c-90a1-758a5dcf24d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1.],\n",
       "       [1., 1., 1.]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建一个和参考数组形状、数据类型相同的数组，并用 1 填充。\n",
    "# np.ones_like(a, dtype=None, order='K', subok=True, shape=None)\n",
    "np.ones_like(np.zeros((2,3)))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0b18b92-f62a-4e15-bf89-6a8497e79feb",
   "metadata": {},
   "source": [
    "#### Empty"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "1f5b67b2-1388-4bcf-83d9-0154b84aace6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1.],\n",
       "       [1., 1., 1.]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建一个2行3列未初始化的数组（随机内存值）\n",
    "# np.empty(shape, dtype=float, order='C')\n",
    "np.empty((2,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90f83cf5-1231-4a91-8554-6b6dda1b0d6f",
   "metadata": {},
   "source": [
    "#### Empty_like"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d4954fba-de2a-46aa-8f3e-615a08e5742c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1.],\n",
       "       [1., 1., 1.]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建一个和参考数组形状、数据类型相同的数组，但不初始化里面的值。\n",
    "# np.empty_like(a, dtype=None, order='K', subok=True, shape=None)\n",
    "np.empty_like(np.zeros((2,3)))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f4c540e-ff76-4891-bcef-cb8133f39901",
   "metadata": {},
   "source": [
    "#### Full "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c87daf5a-f6dd-4a9e-a151-4423bf04354f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([666, 666, 666, 666, 666])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建一个指定形状、指定值的数组。\n",
    "# np.full(shape, fill_value, dtype=None, order='C')\n",
    "np.full(5,666)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93b5bcc8-051b-4269-befe-0633cb454507",
   "metadata": {},
   "source": [
    "#### Full_like"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f6618abd-2015-48bd-a71d-594018a41273",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[666., 666., 666.],\n",
       "       [666., 666., 666.]])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建一个和参考数组形状、类型相同的数组，并用指定的值填充。\n",
    "# np.full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None)\n",
    "np.full_like(np.zeros((2,3)),666)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e848db5-520a-4b95-b988-ba4b81e863e5",
   "metadata": {},
   "source": [
    "#### arange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "b0a735b2-ec87-40a8-a67b-ab7779d9898e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1. , 1.6, 2.2, 2.8, 3.4, 4. , 4.6])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成一个等差数列的数组\n",
    "# np.arange([start,] stop[, step,], dtype=None)\n",
    "np.arange(1,5,0.6)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e36fbda7-cfed-44f5-8a20-eaf6ccd79362",
   "metadata": {},
   "source": [
    "#### reshape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "6a40b5b0-7d7c-4ede-a4d7-ce41527dd51d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2, 3, 4],\n",
       "       [5, 6, 7, 8, 9]])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用来改变数组的形状（维度）而不改变元素的值\n",
    "# np.reshape(a, newshape, order='C')\n",
    "# 链式调用：先 reshape，再转换为 float 类型\n",
    "# b = np.arange(12).reshape(3, 4).astype(float)\n",
    "np.arange(10).reshape((2,5))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c353b49b-20c7-4723-9e1a-440a0d31bdc6",
   "metadata": {},
   "source": [
    "#### linspace\n",
    "**生成一个在指定区间内等间距的数组，可以指定元素数量，而不是步长。**\n",
    "**它和 np.arange 类似，但更适合生成固定数量的点，尤其用于绘图或采样**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "6ddc35da-9c4d-4ec8-87ab-8b16213686e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.        , 1.22222222, 1.44444444, 1.66666667, 1.88888889,\n",
       "       2.11111111, 2.33333333, 2.55555556, 2.77777778, 3.        ])"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 示例：np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)\n",
    "np.linspace(1,3,10,True) # 生成 从 1 到 3 的 10 个等间隔数，包含 1 和 3。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70ab65e6-5b17-4492-9f43-f0a4bd8c3d42",
   "metadata": {},
   "source": [
    "### random \n",
    "**生成各种类型的随机数，包括均匀分布、正态分布、整数、随机排列等，常用于初始化权重、模拟数据或打乱数据顺序。**\n",
    "- 均匀分布：每个数出现的概率相等，没有集中趋势。\n",
    "- 正态分布：是一种连续概率分布，又叫高斯分布。它的概率密度函数呈 “钟形曲线”，数据多集中在平均值附近，两侧逐渐减少。\n",
    "- 左闭右开区间：左边包含右边不包含如`[0, 1)`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e802ddf-1584-4b43-a08d-94717459eab6",
   "metadata": {},
   "source": [
    "#### seed\n",
    "- 用于 设置随机数生成器的种子（Seed）。\n",
    "- 使得随机数序列 可复现：每次运行程序生成的随机数都一样。\n",
    "- 对调试、实验、数据处理等需要可重复结果的场景非常重要。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "b3df4431-0dc4-4705-8b28-55c7f7fe91db",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.89286015, 0.33197981, 0.82122912],\n",
       "       [0.04169663, 0.10765668, 0.59505206]])"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# np.random.seed(seed=None) seed整数，随机种子。如果为 None，随机数生成器使用系统时间或其他熵源，不可复现。\n",
    "np.random.seed(6)\n",
    "np.random.rand(2,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29327919-e031-4c26-903a-013e770c594b",
   "metadata": {},
   "source": [
    "#### rand\n",
    "**生成指定形状的均匀分布随机浮点数数组，数值在 [0, 1) 之间**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "13871620-5a82-4c26-b1da-267d69967f43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[0.40995407, 0.01214465],\n",
       "        [0.66462503, 0.7217401 ],\n",
       "        [0.29676579, 0.42028173]],\n",
       "\n",
       "       [[0.75935979, 0.05951268],\n",
       "        [0.59692913, 0.45463286],\n",
       "        [0.4540855 , 0.09736982]]])"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# np.random.rand(d0, d1, ..., dn)    \n",
    "# d0, d1, ..., dn：数组的维度大小 它返回的是浮点数，并且左闭右开区间 [0, 1)\n",
    "np.random.rand(2,3,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da6e6f3d-7719-4944-b79b-1756ae750cde",
   "metadata": {},
   "source": [
    "#### randn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "b21ac1d6-1611-4b71-92ea-4e39b8ff1c99",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.55375241, -0.12973066, -0.12805678],\n",
       "       [-0.36709872,  0.19649035,  1.63274329]])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成标准正态分布（均值=0，标准差=1）的随机数\n",
    "# np.random.randn(d0, d1, ..., dn)  \n",
    "np.random.randn(2,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "89b86520-9f6a-4c58-81d3-49e70ec7084a",
   "metadata": {},
   "source": [
    "#### random "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "3dfa98d8-5ba1-4214-9ae8-42506008e870",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.92315627, 0.60712958, 0.38943171],\n",
       "       [0.97279484, 0.49713248, 0.76542088]])"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# [0,1) 均匀分布浮点数，size/形状 可选\n",
    "# np.random.random(size=None)\n",
    "np.random.random((2,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "681a9708-ab96-4aa0-afb6-3b331a9f2e05",
   "metadata": {},
   "source": [
    "#### randint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "642a7061-bd05-47f1-a41a-eaff3ada0406",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5, 7, 3],\n",
       "       [4, 3, 6]])"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成 [low, high) 整数随机数/数组\n",
    "# np.random.randint(low, high=None, size=None, dtype=int)\n",
    "np.random.randint(2,9,(2,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23d81340-d56f-4747-a7d0-f9d014dbc8f7",
   "metadata": {},
   "source": [
    "#### normal "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "c1b0d09f-4bfd-4481-98c2-f5d0baf90bc7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2.91900686, 3.01481751, 2.93074135, 2.93206544, 2.98426002,\n",
       "       3.12889822, 3.14522167, 3.02307127, 3.08857929, 3.09653311,\n",
       "       3.02817074, 3.02196928])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成正态分布浮点数，可指定均值和标准差\n",
    "# np.random.normal(loc=0.0, scale=1.0, size=None)\n",
    "np.random.normal(3,0.1,12)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8360c30f-e3f8-40c0-8815-69cb6ebd85d0",
   "metadata": {},
   "source": [
    "#### uniform"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "9633c6f8-cf54-4f7c-85ef-4d05cf0463e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6.04068397, 6.00249789, 5.96929008],\n",
       "       [5.16124786, 7.03590563, 8.95311063],\n",
       "       [5.31733886, 4.74489677, 3.26249362]])"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成均匀分布的随机浮点数,可用于模拟随机实验、初始化参数、生成测试数据等。\n",
    "# 数值在指定的 区间 [low, high) 内随机生成。\n",
    "# np.random.uniform(low=0.0, high=1.0, size=None)\n",
    "np.random.uniform(1,10,(3,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "4a5731bb-90a7-4183-baa7-c22fa12ff95a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method uniform in module numpy.random:\n",
      "\n",
      "uniform(low=0.0, high=1.0, size=None) method of numpy.random.mtrand.RandomState instance\n",
      "    uniform(low=0.0, high=1.0, size=None)\n",
      "\n",
      "    Draw samples from a uniform distribution.\n",
      "\n",
      "    Samples are uniformly distributed over the half-open interval\n",
      "    ``[low, high)`` (includes low, but excludes high).  In other words,\n",
      "    any value within the given interval is equally likely to be drawn\n",
      "    by `uniform`.\n",
      "\n",
      "    .. note::\n",
      "        New code should use the `~numpy.random.Generator.uniform`\n",
      "        method of a `~numpy.random.Generator` instance instead;\n",
      "        please see the :ref:`random-quick-start`.\n",
      "\n",
      "    Parameters\n",
      "    ----------\n",
      "    low : float or array_like of floats, optional\n",
      "        Lower boundary of the output interval.  All values generated will be\n",
      "        greater than or equal to low.  The default value is 0.\n",
      "    high : float or array_like of floats\n",
      "        Upper boundary of the output interval.  All values generated will be\n",
      "        less than or equal to high.  The high limit may be included in the\n",
      "        returned array of floats due to floating-point rounding in the\n",
      "        equation ``low + (high-low) * random_sample()``.  The default value\n",
      "        is 1.0.\n",
      "    size : int or tuple of ints, optional\n",
      "        Output shape.  If the given shape is, e.g., ``(m, n, k)``, then\n",
      "        ``m * n * k`` samples are drawn.  If size is ``None`` (default),\n",
      "        a single value is returned if ``low`` and ``high`` are both scalars.\n",
      "        Otherwise, ``np.broadcast(low, high).size`` samples are drawn.\n",
      "\n",
      "    Returns\n",
      "    -------\n",
      "    out : ndarray or scalar\n",
      "        Drawn samples from the parameterized uniform distribution.\n",
      "\n",
      "    See Also\n",
      "    --------\n",
      "    randint : Discrete uniform distribution, yielding integers.\n",
      "    random_integers : Discrete uniform distribution over the closed\n",
      "                      interval ``[low, high]``.\n",
      "    random_sample : Floats uniformly distributed over ``[0, 1)``.\n",
      "    random : Alias for `random_sample`.\n",
      "    rand : Convenience function that accepts dimensions as input, e.g.,\n",
      "           ``rand(2,2)`` would generate a 2-by-2 array of floats,\n",
      "           uniformly distributed over ``[0, 1)``.\n",
      "    random.Generator.uniform: which should be used for new code.\n",
      "\n",
      "    Notes\n",
      "    -----\n",
      "    The probability density function of the uniform distribution is\n",
      "\n",
      "    .. math:: p(x) = \\frac{1}{b - a}\n",
      "\n",
      "    anywhere within the interval ``[a, b)``, and zero elsewhere.\n",
      "\n",
      "    When ``high`` == ``low``, values of ``low`` will be returned.\n",
      "    If ``high`` < ``low``, the results are officially undefined\n",
      "    and may eventually raise an error, i.e. do not rely on this\n",
      "    function to behave when passed arguments satisfying that\n",
      "    inequality condition. The ``high`` limit may be included in the\n",
      "    returned array of floats due to floating-point rounding in the\n",
      "    equation ``low + (high-low) * random_sample()``. For example:\n",
      "\n",
      "    >>> x = np.float32(5*0.99999999)\n",
      "    >>> x\n",
      "    np.float32(5.0)\n",
      "\n",
      "\n",
      "    Examples\n",
      "    --------\n",
      "    Draw samples from the distribution:\n",
      "\n",
      "    >>> s = np.random.uniform(-1,0,1000)\n",
      "\n",
      "    All values are within the given interval:\n",
      "\n",
      "    >>> np.all(s >= -1)\n",
      "    True\n",
      "    >>> np.all(s < 0)\n",
      "    True\n",
      "\n",
      "    Display the histogram of the samples, along with the\n",
      "    probability density function:\n",
      "\n",
      "    >>> import matplotlib.pyplot as plt\n",
      "    >>> count, bins, ignored = plt.hist(s, 15, density=True)\n",
      "    >>> plt.plot(bins, np.ones_like(bins), linewidth=2, color='r')\n",
      "    >>> plt.show()\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 查看对应方法的文档\n",
    "help(np.random.uniform)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aa255630-bba6-491c-b51e-0e2422b24fa1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
